package com.itheima.day08.myTreeSet.test4;

import java.util.Comparator;
import java.util.TreeSet;

public class Test2 {
    public static void main(String[] args) {
        TreeSet<Teacher> treeSet = new TreeSet<>(new Comparator<Teacher>() {
            @Override
            public int compare(Teacher t1, Teacher t2) {
                int result = t1.getAge() - t2.getAge();
                result = result == 0 ? t1.getName().compareTo(t2.getName()) : result;
                return result;
            }
        });

        Teacher tea1 = new Teacher("zhangsan",25);
        Teacher tea2 = new Teacher("wangwu",23);
        Teacher tea3 = new Teacher("zhangsi",25);
        Teacher tea4 = new Teacher("zhaoliu",21);
        Teacher tea5 = new Teacher("zhangsan",25);
        treeSet.add(tea1);
        treeSet.add(tea2);
        treeSet.add(tea3);
        treeSet.add(tea4);
        treeSet.add(tea5);
        for (Teacher teacher : treeSet) {
            System.out.println(teacher);
        }

    }
}
